A64 - Shortest Path 2
解答
code: python
import heapq
N, M = map(int, input().split())
# (隣接頂点, 重み)
for a, b, c in edges:
INF = 10 ** 10
# 確定した点かどうか
# 暫定値
next = []
# (暫定値, 頂点)
heapq.heappush(next, (0, 1))
while len(next) >= 1:
# 次に確定させるべき頂点を求める
# ここでは、優先度付きキュー next の最小要素を取り除き、その要素の 2 番目の値(頂点番号)を now に代入する
# 小さいのを選べば自ずと確定していく
now = heapq.heappop(next)1 continue
heapq.heappush(next, (anstyouten, tyouten)) for i in range(1, N + 1):
else:
print("-1")